using System;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;

namespace OracleInternal.TTC
{
	internal class TTCEndToEndMetrics : TTCFunction
	{
		internal const short KPDUSR_CID_RESET = 1;

		internal const short KPDUSR_PROXY_RESET = 2;

		internal const short KPDUSR_PROXY_TKTSENT = 4;

		internal const short KPDUSR_MODULE_RESET = 8;

		internal const short KPDUSR_ACTION_RESET = 16;

		internal const short KPDUSR_EXECID_RESET = 32;

		internal const short KPDUSR_EXECSQ_RESET = 64;

		internal const short KPDUSR_COLLCT_RESET = 128;

		internal const short KPDUSR_CLINFO_RESET = 256;

		internal TTCEndToEndMetrics(MarshallingEngine mEngine)
			: base(mEngine, 135, 0)
		{
			m_ttcCode = 17;
		}

		internal void Write(string[] endToEndMetrics, bool[] endToEndMetricsModified)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCEndToEndMetrics, OracleTraceFuncName.Write);
			}
			try
			{
				int num = 0;
				if (endToEndMetricsModified[2])
				{
					num |= 0x10;
				}
				if (endToEndMetricsModified[0])
				{
					num |= 1;
				}
				if (endToEndMetricsModified[1])
				{
					num |= 8;
				}
				if (endToEndMetricsModified[3])
				{
					num |= 0x100;
				}
				WriteFunctionHeader();
				m_marshallingEngine.MarshalNullPointer();
				m_marshallingEngine.MarshalNullPointer();
				m_marshallingEngine.MarshalUB4(num);
				byte[] array = null;
				if (endToEndMetricsModified[0])
				{
					m_marshallingEngine.MarshalPointer();
					if (!string.IsNullOrEmpty(endToEndMetrics[0]))
					{
						array = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(endToEndMetrics[0], 0, endToEndMetrics[0].Length);
						m_marshallingEngine.MarshalUB4(array.Length);
					}
					else
					{
						m_marshallingEngine.MarshalUB4(0L);
					}
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
					m_marshallingEngine.MarshalUB4(0L);
				}
				byte[] array2 = null;
				if (endToEndMetricsModified[1])
				{
					m_marshallingEngine.MarshalPointer();
					if (!string.IsNullOrEmpty(endToEndMetrics[1]))
					{
						array2 = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(endToEndMetrics[1], 0, endToEndMetrics[1].Length);
						m_marshallingEngine.MarshalUB4(endToEndMetrics[1].Length);
					}
					else
					{
						m_marshallingEngine.MarshalUB4(0L);
					}
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
					m_marshallingEngine.MarshalUB4(0L);
				}
				byte[] array3 = null;
				if (endToEndMetricsModified[2])
				{
					m_marshallingEngine.MarshalPointer();
					if (!string.IsNullOrEmpty(endToEndMetrics[2]))
					{
						array3 = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(endToEndMetrics[2], 0, endToEndMetrics[2].Length);
						m_marshallingEngine.MarshalUB4(endToEndMetrics[2].Length);
					}
					else
					{
						m_marshallingEngine.MarshalUB4(0L);
					}
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
					m_marshallingEngine.MarshalUB4(0L);
				}
				m_marshallingEngine.MarshalNullPointer();
				m_marshallingEngine.MarshalUB4(0L);
				m_marshallingEngine.MarshalUB1(0);
				m_marshallingEngine.MarshalUB2(0);
				byte[] array4 = null;
				if (endToEndMetricsModified[3])
				{
					m_marshallingEngine.MarshalPointer();
					if (!string.IsNullOrEmpty(endToEndMetrics[3]))
					{
						array4 = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(endToEndMetrics[3], 0, endToEndMetrics[3].Length);
						m_marshallingEngine.MarshalUB4(endToEndMetrics[3].Length);
					}
					else
					{
						m_marshallingEngine.MarshalUB4(0L);
					}
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
					m_marshallingEngine.MarshalUB4(0L);
				}
				m_marshallingEngine.MarshalNullPointer();
				m_marshallingEngine.MarshalUB4(0L);
				m_marshallingEngine.MarshalNullPointer();
				m_marshallingEngine.MarshalUB4(0L);
				byte[] array5 = null;
				if (m_marshallingEngine.NegotiatedTTCVersion >= 7)
				{
					m_marshallingEngine.MarshalNullPointer();
					m_marshallingEngine.MarshalUB4(0L);
				}
				if (array != null)
				{
					m_marshallingEngine.MarshalCHR(array);
				}
				if (array2 != null)
				{
					m_marshallingEngine.MarshalCHR(array2);
				}
				if (array3 != null)
				{
					m_marshallingEngine.MarshalCHR(array3);
				}
				if (array4 != null)
				{
					m_marshallingEngine.MarshalCHR(array4);
				}
				if (array5 != null)
				{
					m_marshallingEngine.MarshalCHR(array5);
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCEndToEndMetrics, OracleTraceFuncName.Write, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCEndToEndMetrics, OracleTraceFuncName.Write);
				}
			}
		}
	}
}
